package com.hw.common.bean;

import java.io.Serializable;

/*****
 * <pre>
 * 类名称：ResponseBean
 * 类描述：
 * 创建人：JokenWang
 * 创建时间：2015年9月6日 下午3:20:26
 * </pre>
 * 
 * @version 1.0.0
 */
public class ResponseBean<T> implements Serializable
{
    
    private static final long serialVersionUID = 3593827217136880822L;
    
    private static final String DEFAULT_MESSAGE_SUCCESS = "成功";
    
    private static final String DEFAULT_MESSAGE_ERROR = "失败";
    
    private static final String DEFAULT_MESSAGE_NULL = "无数据";
    
    private static final String CODE_SUCCESS = "1";
    
    private static final String CODE_ERROR = "0";
    
    private static final String CODE_NULL = "2";    
    
    private String code;
    
    private String message;
    
    private T data;
    
    public ResponseBean()
    {
        this.code = CODE_SUCCESS;
        this.message = DEFAULT_MESSAGE_SUCCESS;
    }
    
    public void addDefaultError()
    {
        this.code = CODE_ERROR;
        this.message = DEFAULT_MESSAGE_ERROR;
    }
    
    public void addError(String message)
    {
        this.code = CODE_ERROR;
        this.message = message;
    }
    
    public void addError(String code, String message)
    {
        this.code = code;
        this.message = message;
    }
    
    public void addNull()
    {
        this.code = CODE_NULL;
        this.message = DEFAULT_MESSAGE_NULL;
    }
    
    public void addNull(String code,String message)
    {
        this.code = code;
        this.message = message;
    }
    
    public void addNull(String message)
    {
        this.code = CODE_NULL;
        this.message = message;
    }
    
    public void addSuccess()
    {
        this.code = CODE_SUCCESS;
        this.message = DEFAULT_MESSAGE_SUCCESS;
    }
    
    public void addSuccess(T data)
    {
        this.code = CODE_SUCCESS;
        this.message = DEFAULT_MESSAGE_SUCCESS;
        this.data = data;
    }
    
    public T getData()
    {
        return data;
    }
    
    public final String getCode()
    {
        return code;
    }
    
    public final String getMessage()
    {
        return message;
    }
    
    @Override
    public String toString()
    {
        StringBuilder builder = new StringBuilder();
        builder.append("ResponseBaseBean [code=");
        builder.append(code);
        builder.append(", message=");
        builder.append(message);
        builder.append(", data=");
        builder.append(data);
        builder.append("]");
        return builder.toString();
    }
}
